from frame.api.client.base_client import BaseClient

'''购物车接口的实现'''
class BaseCart(BaseClient):
    cart_url = "cart/"
    goods_url = "goods/"

    def list_goods(self, goods_name):
        """
        查询商品接口的实现
        :return:
        """
        # 请求数据
        param_data = {
            "keyword": goods_name,
            "page": 1,
            "limit": 10,
            "categoryId": 0
        }
        # 定义请求参数
        list_req = {
            "url": self.goods_url + "list",
            "method": "GET",
            "params": param_data,
        }
        # 发起请求
        list_res = self.send_api(list_req)
        return list_res.json()

    def add_goods_to_cart(self, goods_id):
        """
        添加商品到购物车接口的实现
        :param goods_id:商品ID
        :return:
        """
        # 请求数据
        add_data = {
            "goodsId": goods_id,
            "number": 2,
            "productId": 1813
        }
        # 定义请求参数
        add_req = {
            "url": self.cart_url + "add",
            "method": "POST",
            "json": add_data,
        }

        add_res = self.send_api(add_req)
        return add_res.json()
